package com.cqu.lpss.controller;

import com.cqu.lpss.mapper.ContestantsMapper;
import com.cqu.lpss.pojo.Contestants;
import com.cqu.lpss.pojo.Projects;
import com.cqu.lpss.pojo.Result;
import com.cqu.lpss.service.impl.ContestantsImpl;
import com.cqu.lpss.service.impl.ProjectImpl;
import com.cqu.lpss.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    ProjectImpl projectimpl;
    @Autowired
    AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result upload(@RequestPart(value = "file") MultipartFile uploadfile) throws IOException {
        log.info("文件：{}",uploadfile);
        log.info("文件上传，文件名：{}", uploadfile.getOriginalFilename());
        //阿里云工具类进行文件上传
        String url = aliOSSUtils.upload(uploadfile);
        log.info("文件上传完成，文件访问的url:{}",url);
        return Result.success(url);
    }
    @GetMapping("/find")
    public Result findByConId(@RequestParam String ConId){
        log.info("conId:{}",ConId);
        Projects prj = projectimpl.findByConId(ConId);
        if(prj!=null){
            return  Result.success(prj);
        }else {
            return Result.erro("NOTUPLOAD");
        }
    }
    @PostMapping("/submit")
    public Result submit(@RequestBody Projects project){
        log.info("project:{}",project);
        int ans = projectimpl.submit(project);
        if(ans!=0){
            return Result.success();
        }else {
            return Result.erro("INSERT_ERRO");
        }
    }
    @PostMapping("/publishfirstGrade")
    public Result publishfirstGrade(){
        int ans = projectimpl.modifyPrjPublishFirstGrade();
        return Result.success(ans);
    }
    /**
     * @Description:查询不允许发布成绩的有多少，如果为0则表示成绩已发布，成绩不为0表示不允许查询，即还未发布
     * @Param:[]
     * @Return: com.cqu.lpss.pojo.Result
     * @Date: 2024/5/9
     * @Author:liuyawen
     */

    @PostMapping("/havepublishfirstGrade")
    public Result havepublishfirstGrade(){
        int ans = projectimpl.havepublishfirstGrade();
        return Result.success(ans);
    }
    @PostMapping("/firstscorequery")
    public Result firstscorequery(@RequestParam String conId){
        Projects firstscorequery = projectimpl.firstscorequery(conId);
        if(firstscorequery!=null){
            return Result.success(firstscorequery);
        }else {
            return Result.erro("查询不到");
        }

    }
    @PostMapping("/passfirstPrj")
    public Result passfirstPrj(){
        List<Projects> passfirstPrjs = projectimpl.passfirstPrj();
        if(passfirstPrjs==null){
            return Result.erro("无数据");
        }else {
            return  Result.success(passfirstPrjs);
        }
    }
    @PostMapping("/updatepublishfinalscore")
    public Result updatepublishfinalscore(){
        int ans = projectimpl.updatepublishfinalscore();
        return Result.success(ans);
    }
    @PostMapping("/havepublishfinalscore")
    public Result havepublishfinalscore(){
        int ans = projectimpl.havepublishfinalscore();
        return Result.success(ans);
    }
    @PostMapping("/finalscorequery")
    public Result finalscorequery(@RequestParam String conId){
        Projects project = projectimpl.finalscorequery(conId);
        return Result.success(project);
    }
    @PostMapping("/passfinalPrj")
    public Result passfinalPrj(){
        log.info("passfinalPrj");
        List<Projects> passfinalPrjs = projectimpl.passfinalprj();
        if(passfinalPrjs!=null){
            return Result.success(passfinalPrjs);
        }else {
            return  Result.erro("None");
        }

    }
}
